<?php
	$topic_id = $params[0];
	extract(select('v_webboard','topic_id',$topic_id,"AND `status` = '1'"), EXTR_PREFIX_ALL , "c");
	$c_time = formatDate($c_date,'H:i:s');
	$c_date = formatDate($c_date,'Y/m/d');

	if($ss_member_id){
		$tp->block('user');
	}else{
		$tp->block('nonuser');
	}
	$tp->Apply();

	if($_SERVER["REQUEST_METHOD"]=="POST") {
		$title		= strip_tags($_POST['title']);
		$detail		= $_POST['detail'];
		$keyword	= keyword($detail);
		$ip			= getUserIP();
		$sql		= "INSERT INTO `tbl_webboard_reply` (`reply_id`, `topic_id`, `member_id`, `detail`, `date`, `status`) VALUES (NULL, '$c_topic_id', '$ss_member_id', '$detail', NOW(), '1');";
		mysql_query($sql);
		redirect('');
		exit;
	}
	
	$p = strip_tags($_GET['p']);
	$l = 3;
	$rn =0;
	$rn = $p <= 1 ? $rn : $l * ($p-1);
	list($sql,$all_page) = splitPage("`v_webboard_reply`","`topic_id` = '$c_topic_id' AND `status` = '1' ORDER BY `date` ASC", $l, $p);
	$strPage = fetchPage($all_page,$p);
	$query = mysql_query($sql);
	$tp->block('reply');
	while($result = mysql_fetch_assoc($query)) {
		$rn++;
		$r_reply_id	= $result['reply_id'];
		$r_date		= $result['date'];
		$r_detail	= $result['detail'];
		$r_username	= $result['username'];
		$r_time		= formatDate($r_date,'H:i:s');
		$r_date		= formatDate($r_date,'Y/m/d');
		$tp->apply();
	}
	mysql_free_result($query);

	$sql = "INSERT INTO `tbl_webboard_view` (`view_id`, `topic_id`, `member_id`, `date`, `ssid`) VALUES (NULL, '$c_topic_id', '$ss_member_id', NOW(), '$ss_id');";
	mysql_query($sql);
?>